package api.google.android;

import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.TextView;

public class ListView extends ListActivity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		String groupName = "";
		Bundle extras = getIntent().getExtras();
		if(extras !=null) {
			groupName = extras.getString("groupName");
		}
		
		Connection connection = new Connection("groupMembers");
		connection.addPostData("group", groupName);
        String jsonResponse = connection.postData();
        ParseJSON jsonParser = new ParseJSON();
        List<String> members = jsonParser.JsonArrayToList(jsonResponse);
        
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, members));

		android.widget.ListView listView = getListView();
		listView.setTextFilterEnabled(true);
		listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
			}
		});
	}
}
